package com.songshu.e.dubbo.api.controller;

import com.songshu.e.dubbo.api.service.AdService;
import com.songshu.e.dubbo.api.vo.WebResult;
import com.songshu.e.dubbo.server.pojo.Ad;
import com.songshu.e.dubbo.server.vo.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("ad")
@RestController
@CrossOrigin
public class AdController {

    @Autowired
    private AdService adService;
    //查询首页的广告
    @GetMapping
    public WebResult queryIndexAd(){
        PageInfo<Ad> adPageInfo = adService.queryAdList(1, 1, 3);
        List<Object> url = new ArrayList<>();
        adPageInfo.getRecords().forEach(record->{
            Map<String,Object> original = new HashMap<>();
            original.put("original",record.getUrl());
            url.add(original);
        });
        return WebResult.ok(url);
    }
}
